package hmis.pos.Repository;

import hmis.pos.Base.BaseRepository.BaseRepository;
import hmis.pos.Entity.Order;
import hmis.pos.Entity.RoomPrice;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface OrderRepository extends BaseRepository<Order> {

    @Query(value = "select * from roomorder where status = ?1", nativeQuery = true)
    List<Order> findByStatus(String status);

    //查找入住时间为今天的订单
    @Query(value = "select * from roomorder where ?1 between in_time and out_time", nativeQuery = true)
    List<Order> findByToday(Date today);

    //查找今天创建的订单
    @Query(value = "select * from roomorder where to_days(create_time) = to_days(now());", nativeQuery = true)
    List<Order> findByToday2();

    //查找今年创建的订单
    @Query(value="SELECT * FROM roomorder WHERE YEAR(create_time) = YEAR( NOW( ) ) ", nativeQuery = true)
    List<Order> findByYear();

    //查找这个月创建的订单
    @Query(value="SELECT * FROM roomorder WHERE DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ),'%Y%m')", nativeQuery = true)
    List<Order> findByMonth();

    //一周内创建的订单
    @Query(value="SELECT * FROM roomorder where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(create_time)", nativeQuery = true)
    List<Order> findByWeek();
}


